﻿Ext.define('app.prm.project_task.ChooseTag',
{
    extend: 'Ext.window.Window',
    title: '选择标签',
    autoScroll: true,
    modal: true,
    width: 700,
    height: 600,
    projectId: 0,
    textValue: '',
    Tags: '',
    initComponent: function () {
        var me = this;
        me.items = [
            me.getTagForm(),
            me.getTagPanel()
        ];
        me.buttons = [
            { text: '确定', scope: this, handler: me.onSave },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    getTagForm: function () {
        var me = this;
        if (!this.tagForm) {
            this.tagForm = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '95%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "top",
                    flex: 1,
                    margin: 6
                },
                items: [
                    { xtype: 'textarea', name: 'txt_tag', fieldLabel: '已选择标签', value: me.Tags, height: 150 }
                ]
            });
        }
        return this.tagForm;
    },
    getTagPanel: function () {
        var me = this;
        if (!this.tagPanel) {
            me.tagStore = Ext.create("app.ux.PrmStore", { url: '/api/services/app/projectTask/GetTaskTags?projectId=' + me.projectId });
            this.tagPanel = Ext.create("app.ux.TagCloud",
            {
                displayWeight: false,
                displayField: 'key',
                weightField: 'value',
                listeners: {
                    tagselect: function (tagcloud, record) {
                        var txt_tag = me.tagForm.query("textarea[name=txt_tag]")[0];
                        txt_tag.setValue(txt_tag.getValue() + record.data.key + ",");
                    }
                }
            });
            this.tagPanel.setStore(me.tagStore);
        }
        return this.tagPanel;
    },
    onSave: function () {
        var me = this;
        var tag = me.tagForm.query("textarea[name=txt_tag]")[0].getValue();
        me.fireEvent("savesuccess", tag);
    }
});